/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using ELE.EnterpriseLibrary.Data.Configuration.Design.Properties;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Configuration;

namespace ELE.EnterpriseLibrary.Data.Configuration.Design
{

  [Image(typeof(QueryBuilderNode))]
  [SelectedImage(typeof(QueryBuilderNode))]
  public class QueryBuilderNode : ConfigurationNode
  {
    private Type type;
    private bool isDefault = false;

    public QueryBuilderNode()
	    : this(new QueryBuilderData(Resource.DefaultQueryBuilderNodeName))
    {
        
    }

    public QueryBuilderNode(QueryBuilderData builderData)
      : base((builderData == null) ? Resource.DefaultQueryBuilderName : builderData.Name)
    {
      if (builderData == null) { throw new ArgumentNullException("QueryBuilderData"); }

      this.isDefault = builderData.Default;
      this.type = Type.GetType(builderData.Type);
    }		

    [Browsable(false)]
    public QueryBuilderData QueryBuilderData
    {
      get
      {
        QueryBuilderData data = new QueryBuilderData(Name);
        data.Default = this.isDefault;
        data.Type = this.type.AssemblyQualifiedName;
	      return data;
      }
    }

    [Required]
    [SRDescription("QueryBuilderNodeTypeDescription", typeof(Resource))]
    [Editor(typeof(TypeSelectorEditor), typeof(UITypeEditor))]
    [BaseType(typeof(ISqlQueryBuilder))]
    [SRCategory("CategoryGeneral", typeof(Resource))]
    public Type Type
    {
      get { return type; }
      set { type = value; }
    }

    [Required]
    [SRDescription("DefaultQueryBuilderDescription", typeof(Resource))]
    [SRCategory("CategoryGeneral", typeof(Resource))]
    public bool IsDefault
    {
      get { return isDefault; }
      set { isDefault = value; }
    }
	}
}